<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./axios.js"></script>
</head>
<body>
    <h1>需要鉴权才能获取数据</h1>
    <script>
        console.log( axios.interceptors.request.use());
        axios.interceptors.request.use(config=>{
            config.headers.Authorization = localStorage.getItem("token")
            return config;
        });
        // axios.interceptors.request.use(config=>{
        //     config.headers.Authorization = localStorage.getItem("token")    // 可以给所有的请求头部加上  token
        //     return config;
        // })
        (async function(){
            // 头部携带token 发送给服务端校验是否正确；
           let {data} =  await axios.get("/getlist",{
            // headers:{
            //     Authorization:localStorage.getItem("token")   // 获取localstroage里存储的token
            // }
           });
           console.log(data);
           data.forEach(item=>{
            let pEle = document.createElement("p");
            pEle.innerHTML = item.name;
            document.body.appendChild(pEle);
           })
        })();



    </script>
</body>
</html>